package com.jsy.mini12306.ticketsales.controller;

import com.jsy.mini12306.common.entity.Train;
import com.jsy.mini12306.ticketsales.service.TrainService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 车次（图中的路径）(Train)表控制层
 *
 * @author: SongyangJi
 * @since: 2021-09-01 12:55:07
 * @description: 车次查询服务
 */

@Slf4j
@RestController
@RequestMapping("train")
public class TrainController {
    /**
     * 服务对象
     */
    @Resource
    private TrainService trainService;

    /**
     * 管理员
     *
     * @return 所有车次（不论状态）
     * <p>
     * 可做成分页
     */
    @GetMapping("/all")
    public ResponseEntity<List<Train>> listAllTrains() {
        return ResponseEntity.ok(trainService.listAllTrains().subList(0,10));
    }

    @GetMapping("/trainId/{trainId}")
    public ResponseEntity<Train> getTrainById(@PathVariable int trainId) {
        Train train = trainService.queryTrainById(trainId);
        return ResponseEntity.ok(train);
    }


    @GetMapping("/trainName/{trainName}")
    public ResponseEntity<Train> getTrainByName(@PathVariable String trainName) {
        return ResponseEntity.ok(trainService.queryTrainByTrainName(trainName));
    }


}
